import {apiEditPasswordSystemUser} from "~/api/user";
import util from "~/tool/common";

let loading = ref(false);

export default function useStoragePassword(router, route) {
    const savePasswordData = (value) => {
        if (util.isEmpty(value.password) || util.isEmpty(value.id)) {
            ElMessage.warning('请检查数据填写是否完整');
            return true;
        }


        loading.value = true;
        apiEditPasswordSystemUser(value).then(() => {
            ElMessageBox.confirm('保存成功, 是否返回存储源列表？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'success',
                callback: action => {
                    if (action === 'confirm') {
                        router.push('/admin/user-list');
                    }
                }
            });
        }).finally(() => {
            loading.value = false;
        });
    }

    return {
        loading,savePasswordData
    }
}